package com.example.video.fg

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.BannerVideoEntityResult
import com.example.base.entity.TypeVideoEntityResult
import com.example.base.entity.VideoEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class HomeViewModel:BaseViewModel() {
    //返回值
    val bannerSuccess = MutableLiveData<BannerVideoEntityResult>()
    val bannerFail = MutableLiveData<String>()
    fun bannerVideo(){
        viewModelScope.launch {
            try {
                bannerSuccess.value = apiServer.bannerVideo()
            }catch (e:Exception){
                bannerFail.value = e.message
            }
        }
    }
    //返回值---分类
    val typeSuccess = MutableLiveData<TypeVideoEntityResult>()
    val typeFail  = MutableLiveData<String>()
    fun typeVideo(){
        viewModelScope.launch {
            try {
                typeSuccess.value = apiServer.typeVideo()
            }catch (e:Exception){
                typeFail.value = e.message
            }
        }
    }
    //返回值--视频
    val videoSuccess  = MutableLiveData<VideoEntityResult>()
    val videoFail = MutableLiveData<String>()
    fun video(channelId:String,page:Int,pagesize:Int){
        viewModelScope.launch {
            try {
                videoSuccess.value = apiServer.video(channelId, page, pagesize)
            }catch (e:Exception){
                videoFail.value = e.message
            }
        }
    }
}